<template>
  <div class="main">
    <div class="title">{{decodeURIComponent(name)}}</div>
    <img :src="$store.state.appBg" class="bg1" alt>
    <div class="main-container">
      <scroll-container ref="scrollContainer">
        <div class="container-list">
          <multi-list @scrollTo="scrollTo" :groupDatas="groupDatas">
            <imglist_w384_2 :groupData="groupDatas.dataArr[0]" :focArr="groupDatas.focArr[0]" :group="groups[0]"></imglist_w384_2>
          </multi-list>
        </div>
      </scroll-container>
    </div>
  </div>
</template>

<script>
  import scrollContainer from "@/components/base/scroll-container/scroll-container";
  import multiList from "@/components/base/multi-list/multi-list";
  import Navigation from "@/components/Navigation";
  import imglist_w384_2 from "../ImgList_w384_2";

  export default {
    name: "xgkk",
    components: {
      Navigation,
      scrollContainer,
      multiList,
      imglist_w384_2
    },
    data() {
      return {
        folderCode: this.$route.params.folderCode,
        name: this.$route.params.name,
        groups: [0, 1],
        scrollY: 0,
        backObjName: "msgkk-list-in",
        hs: this.$store.state.hs,
        bridge: this.$store.state.bridge,
        groupDatas: {
          dataArr:[
            {
              maxLine: 4,
              dynamic: true,
              title: "",
              data: [],
              focObj: []
            }
          ],
          focArr: [[]]
        }
      };
    },
    methods: {
      scroll(pos) {
        this.scrollY = pos.y;
        // console.log(pos);
      },
      scrollTo(targetIndex) {
        //console.log("targetIndex", targetIndex);
        this.$refs.scrollContainer.scrollTo(targetIndex);
      },
      setBackObj(backObj) {
        this.hs.cookie.set(this.backObjName, JSON.stringify(backObj));
      },
      getData1() {
        let url = "http://ips-4k.hzdtv.tv/dataquery/folderContents?folderCode=" + this.folderCode + "&pageItems=25&cImageMode=255,339,JPG&fields=assetType&segmentIndex=1&pageIndex=" + (this.hs.focObj.objindex + 1);
        this.hs.ajax.post(
          "http://125.210.113.145/WSL/Core/CrossDomain.ashx",
          "url=" + encodeURIComponent(url) + "&data=&method=get&type=default",
          obj => {
            obj = JSON.parse(obj);
            //console.log(obj);
            this.groupDatas.dataArr[0].data = obj.contents
          },
          0,
          function (msg) {
          },
          3000
        );
      }
    },

    created() {
      this.getData1();
    },
    mounted() {
      this.hs.addSelect(this.groups, (group, objid, objindex) => {
        let url = "http://ips-4k.hzdtv.tv/dataquery/gotoAuthPlay?folderCode=" + this.folderCode + "&contentId=" + this.groupDatas.dataArr[0].data[objindex].contentId
          + "&contentType=" + this.groupDatas.dataArr[0].data[objindex].contentType;
        this.hs.ajax.get(url, (_responseText) => {
          let res = eval("(" + _responseText + ")");
          //console.log(res);
          if (res.result == "0" || res.result == 0) {
            if (res.authResult == 0) {
              let url = "http://ips-4k.hzdtv.tv/dataquery/contentPlayUrl?folderCode=" + this.folderCode + "&contentId=" + this.groupDatas.dataArr[0].data[objindex].contentId
                + "&contentType=" + this.groupDatas.dataArr[0].data[objindex].contentType + '&playUrlType=rtsp';
              this.hs.ajax.get(url, (_responseText) => {
                let res = eval("(" + _responseText + ")");
                this.bridge.gotoApplication2play(res.playUrl)
              }, 0, 3000);
            } else {
              this.bridge.gotoApplication2order({
                ppvId: res.ppvId,
                columnAlias: this.folderCode
              })
            }
          }
        }, 0, 3000);
      });

      this.hs.initFocus("0-0");

      //  查看是否有记忆焦点
      if (this.hs.cookie.get(this.backObjName)) {
        let backObj = JSON.parse(this.hs.cookie.get(this.backObjName));
        let focArr = backObj.backFocArr;
        this.hs.cookie.delOne(this.backObjName);
        // console.log(JSON.stringify(focArr) + "**************");
        this.hs.initFocus(focArr[0], true);
      }

      this.bridge.whenKeyBack = () => {
        // 当页面显示的时候就返回首页, 隐藏的时候, 就显示页面
        if (this.$store.state.appShow) {
          window.history.go(-1);
        } else {
          this.$store.commit("setAppShow", true);
        }
      };
    }
  };
</script>

<style scoped lang="less">
.main {
  width: 1920px;
  height: 1080px;
  overflow: hidden;
  .bg1 {
    position: absolute;
    top: 0;
    z-index: -1;
  }
  .title {
    text-align: right;
    margin-top: 77px;
    margin-right: 120px;
    font-family: MicrosoftYaHei;
    font-size: 60px;
    line-height: 60px;
    letter-spacing: 0px;
    color: #a8e7ff;
  }
  .main-container {
    margin-left: 72px;
    margin-top: 0px;
    height: 930px;
    .multi-container {
      padding-left: 48px;
      padding-top: 48px;
    }
  }
}
</style>
